<?php
include_once('xcx_sqlclass.php');
$mysql=new MMsql();
class commonfun{
	public $mysql;
	function __construct(){
		
		//$this->sqldh=$mysql;
		
	}
	
	public function creatId($type){ 
		$fp= fopen("lock.txt", "w+");
		if(flock($fp,LOCK_EX)){//排它锁
			$sql="select * from wk_id_key where id_type='".$type."'";
			$list=$GLOBALS['mysql']->doSql($sql);
			$aa=$list[0]['maxval'];
			//echo $aa."<br/>";
			$m=$aa + 1;
			$sql2="update wk_id_key set maxval = $m where id_type='".$type."' and maxval<$m";
			$b=$GLOBALS['mysql']->doSql($sql2);
			flock($fp,LOCK_UN);//释放锁
			fclose($fp);
			return $aa;
		}
	}
	/**
	 * 返回微秒时间戳
	*/
	public function msecTime() {
		list($msec, $sec) = explode(' ', microtime());
		$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
		return $msectime;
	}
	
	
}